package com.woniuxy.education.utils;

import com.woniuxy.education.entity.*;
import com.woniuxy.education.mapper.StudentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * 封装了一个工具类,用于将题目遍历出来
 * 以及将题目的id遍历出来
 */
@Component
public  class Titles {
    private static Titles titles;
    @Autowired
    private StudentMapper studentMapper;
    @PostConstruct
    public  void init(){
        titles=this;
    }
    public static AllTitle allTitle(Titleids titleids){
        //这里将题目的id纪律下来,传给前端,用于用户提交后可以直接根据id来修改题目状态,做没做过
        Allquestionsid allquestionsid=new Allquestionsid();
        //选择题
        List listCT=new ArrayList();
        //选择题对应的题目id
        List  listCTid=new LinkedList();
        //填空题
        List listCLT= new ArrayList();
        //填空题对应的题目id
        List  listCLTid=new LinkedList();
        //解答题
        List listAQT=new ArrayList();
        //解答题对应的题目id
        List  listAQTid=new LinkedList();
        //作文
        List listCST=new ArrayList();
        //作文题对应的题目id
        List  listCSTid=new LinkedList();
        AllTitle allTitles=new AllTitle();

        String choose[]= titleids.getChoose().split(",");
        //查询选择题
        if(choose.length>0){
            for(int i=0;i<choose.length;i++){
                Choose_table ch =titles.studentMapper.findChoose(Integer.parseInt(choose[i]));
                listCT.add(ch);
            }
            allTitles.setListCT(listCT);
            allquestionsid.setCtid(titleids.getChoose());
        }

        String completion[]= titleids.getCompletion().split(",");
        //查询填空题
        if(completion.length>0){
            for(int i=0;i<completion.length;i++){
                Completion_table clt =titles.studentMapper.findCompletion(Integer.parseInt(completion[i]));
                listCLT.add(clt);
            }
            allTitles.setListCLT(listCLT);
            allquestionsid.setCltid(titleids.getCompletion());
        }

        String answer_ques[]= titleids.getAnswer_questions().split(",");
        //查询解答题
        if(answer_ques.length>0){
            for(int i=0;i<answer_ques.length;i++){
                Answer_Questions_table aqt =titles.studentMapper.findAnswer_Questions(Integer.parseInt(answer_ques[i]));
                listAQT.add(aqt);
            }
            allTitles.setListAQT(listAQT);
            allquestionsid.setAqtid(titleids.getAnswer_questions());
        }

        String composition[]= titleids.getComposition().split(",");
        //查询作文题
        if(composition.length>0){
            for(int i=0;i<composition.length;i++){
                Composition_table cst =titles.studentMapper.findComposition(Integer.parseInt(composition[i]));
                listCST.add(cst);
            }
            allTitles.setListCST(listCST);
            allquestionsid.setCstid(titleids.getComposition());
        }
        allTitles.setAllquestionsid(allquestionsid);
        return allTitles;
    }
}
